package listener.other;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class AchieveEventManager {

    private static final AchieveEventManager achieveEventManager = new AchieveEventManager();

    private static final Map<Integer, List<AchieveEvent>> achieveEventMap = new HashMap<>();

    public static AchieveEventManager getInstance() {
        return achieveEventManager;
    }

    public void addEvent(int eventId, AchieveEvent achieveEvent) {
        List<AchieveEvent> achieveEvents = achieveEventMap.computeIfAbsent(eventId, k -> new ArrayList<>());
        achieveEvents.add(achieveEvent);
    }

    public void taggerEvent(int eventId, int process) {
        List<AchieveEvent> achieveEvents = achieveEventMap.get(eventId);
        if (achieveEvents == null || achieveEvents.isEmpty()) {
            return;
        }
        achieveEvents.forEach(e -> {
            if (e.taggerEvent(eventId, process)) {
                System.out.println("触发成就：" + e.getId());
            }
        });
    }

}
